<?php
require_once("connect_db.php");
$username=trim($_POST["username"]," ");
$password=trim($_POST["password"]," ");
$numsStudent=0;$numsAdmin=0;$numsTeacher=0;
$sqlLg="select CONCAT(std_name,' ',std_lname) As Name,role,std_Pic,std_id from student where user_name='".$username."' and password='".$password."' ORDER BY std_id DESC LIMIT 1";
$queryLg=mysql_query($sqlLg,$conn);
$numsStudent=mysql_num_rows($queryLg);
if($numsStudent==0)
{
$sqlLg="select user_name,role,CONCAT('administrator.jpg') As pics,ad_id from admin where user_name='".$username."' and password='".$password."'  LIMIT 1";
$queryLgAdmin=mysql_query($sqlLg,$conn);
$numsAdmin=mysql_num_rows($queryLgAdmin);
}
if($numsAdmin==0&&$numsStudent==0)
{
$sqlLg="select CONCAT(teach_name,' ',teach_lname) As Name,role,teach_pic,teach_id  from teacher where user_name='".$username."' and password='".$password."' ORDER BY teach_id DESC LIMIT 1";
$queryLgTeacher=mysql_query($sqlLg,$conn);
$numsTeacher=mysql_num_rows($queryLgTeacher);
}

$queryReal=mysql_query($sqlLg,$conn);

if($numsStudent==0&&$numsAdmin==0&&$numsTeacher==0)
echo "0";
else{
@session_start();
$result=mysql_fetch_row($queryReal);
$_SESSION["account_name"]=$result[0];
$_SESSION["role"]=$result[1];
$_SESSION["pics"]=$result[2];
$_SESSION["id"]=$result[3];
echo "user_login/";
}
?>